#include "forecast_dialog.h"
#include "ui_forecast_dialog.h"

forecast_Dialog::forecast_Dialog(QMap<QString,City>& cit,QSet<QString> &City_name, QSet<QString> &Country_name, QWidget *parent) :
    QDialog(parent),
    ui(new Ui::forecast_Dialog),
    city(cit),
    city_name(City_name),
    country_name(Country_name)
{
    ui->setupUi(this);
    for(auto e : city_name)
    {
     ui->comboBox_city->addItem(e);
    }
    for(auto e : country_name)
    {
     ui->comboBox_country->addItem(e);
    }
}
forecast_Dialog::~forecast_Dialog()
{
    delete ui;
}

void forecast_Dialog::on_pushButton_2_clicked()
{
    this->close();
}

void forecast_Dialog::on_pushButton_clicked()
{
    QString country = ui->comboBox_country->currentText();
    QString name = ui->comboBox_city->currentText();
    QVector<double> y;
    for(auto e : city)
    {
        if(e.get_name() == name && e.get_country() == country)
        {
            y.push_back((double)e.get_new());
        }
    }
    if(y.size() == 0) return;
    QVector<double> x;
    for(int i = 1; i <= y.size(); i++)
    {
        x.push_back((double)i);
    }
    Network n(5,y.size());
    n.readTrainData(x.data(),y.data());
    n.RNNTrain(1000);
    QStringList ret = n.RNNShowResult();
    ui->textEdit->setText(ret.join(QLatin1String("\n")));
}
